package CtrLayer;

import DBLayer.DBBradenScale;

import DomainLayer.*;
import DBLayer.*;
import java.util.ArrayList;
public class SchemeCtr {

	private IFDBLabScheme dbLabScheme;
	private IFDBBradenScale dbBradenScale;
	private IFDBNutRiskScheme dbNutRiskScheme;
	private IFDBTemperatureScheme dbTempScheme;
	private DBNursingDocumentation dbNursingDocumentation;
	private DBJournal dbJournal;

	public SchemeCtr() {

		dbLabScheme = new DBLabScheme();
		dbBradenScale = new DBBradenScale();
		dbNutRiskScheme = new DBNutRiskScheme();
		dbTempScheme = new DBTemperatureScheme();
		dbNursingDocumentation = new DBNursingDocumentation();
		dbJournal=new DBJournal();
	}

	public ArrayList<LabSchemeMeasurement> getAllLabSchemeMeasurements(String name) {
		return this.dbLabScheme.getAllLabSchemeMeasurements(name);

	}

	public NutritionRiskScheme findNutritionRiskScheme(String name ) {
		return this.dbNutRiskScheme.getScheme(name);
	}

	public BradenScale findBradenScale(String name) {
		return dbBradenScale.getScheme(name);
	}

	public ArrayList<TemperatureSchemeMeasurement> getAllTemperatureSchemeMeasurements(String name) {
		return dbTempScheme.getAllTemperatureSchemeMeasurements(name);
	}

	public void createLabScheme(String name, String date, String hemoglobin, String leukocytter,
			String thrombocytter, String koagulationsfaktorer, String ph,
			String base_excess, String oxygen, String hydrogencarbonation,
			String kalium, String natrium, String creatininium,
			String carbamid, String albumin, String creaktivtprotein,
			String glucose0600, String glucose1200, String glucose1730,
			String glucose2130,String syre_base_status) {
		LabSchemeMeasurement scheme = new LabSchemeMeasurement(name ,date, hemoglobin, leukocytter,
				thrombocytter, koagulationsfaktorer, ph, base_excess, oxygen,
				hydrogencarbonation, kalium, natrium, creatininium, carbamid,
				albumin, creaktivtprotein, glucose0600, glucose1200,
				glucose1730, glucose2130,syre_base_status);

		try {
			dbLabScheme.createScheme(scheme);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	 public ArrayList<NursingDocumentation> getNursingDocumentation(String name)
	 {
	  
	  return dbNursingDocumentation.getAllNursingDocumentationParts(name);
	 
	  
	  
	 }

	public void createBardenScale(String name,int sensoryPerception, int moisture,
			int activity, int mobility, int nutrition, int frictionAndShear) {

		BradenScale scale = new BradenScale( name, sensoryPerception, moisture,
				activity, mobility, nutrition, frictionAndShear);
		try {
			dbBradenScale.createScheme(scale);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void createNursingDocumentation(String name,String communication,String development,String respiration_circulation,String nutrition,
			String excretion,String skin_tissue,String activity,String sleep,String pain_sensation,
			String sexuality_reproduction,String psychsocial,String spiritual_cultural,String date)
	{
		NursingDocumentation nursingDocumentation= new NursingDocumentation(name,communication, development, respiration_circulation, nutrition, excretion, skin_tissue, activity, sleep, pain_sensation, sexuality_reproduction, psychsocial, spiritual_cultural,date);
	DBNursingDocumentation dbND= new DBNursingDocumentation();
	try{
	dbND.createNursingDocumentation(nursingDocumentation);
	}
	catch(Exception e)
	{
		System.out.println("exception catched trying to create nursing documentation");
	}
	
	}

	public void createNutritionRiskScheme(String name, int impNutritionStatus,
			int severityOfDisease) {
		NutritionRiskScheme scheme = new NutritionRiskScheme(name,
				impNutritionStatus, severityOfDisease);
		dbNutRiskScheme.createScheme(scheme);
	}

	public void createTempScheme(String nameScheme,int puls, int blood_pressure_systolic,
			int blood_pressure_diastolic, String datetime, int temperature,
			int respiration) {

		TemperatureSchemeMeasurement scheme = new TemperatureSchemeMeasurement(nameScheme,puls,
				blood_pressure_systolic, blood_pressure_diastolic, datetime,
				temperature, respiration);
		dbTempScheme.createScheme(scheme);
	}

	public void deleteLabScheme(String name) {

		dbLabScheme.deleteScheme(name);
	}

	public void deleteBradenScale(String name) {

		dbBradenScale.deleteScheme(name);
	}

	public void deleteTemperatureScheme(String name	) {

		dbTempScheme.deleteScheme(name);
	}

	public void deleteNutritionRiskScheme(String name) {
		dbNutRiskScheme.deleteScheme(name);
	}

	public void updateLabScheme(LabSchemeMeasurement labScheme) {
		dbLabScheme.updateScheme(labScheme);
	}

	public void updateBradenScale(BradenScale scale) {
		dbBradenScale.updateScheme(scale);
	}

	public void updateTemperatureScheme(TemperatureSchemeMeasurement tempScheme) {
		dbTempScheme.updateScheme(tempScheme);
	}

	public void updateNutritionRiskScheme(NutritionRiskScheme nutRiskScheme) {
         dbNutRiskScheme.updateScheme(nutRiskScheme);
	}

	 public String[][] getAllBradenScalesInformation()
	 {
		 
      	
		ArrayList<BradenScale> scales= dbBradenScale.getAllBradenScales();
		
		String [][] scalesInfo = new String [scales.size()][7]; //Initialize a two dimensional array with the number of scales and number of variables each scale has
		
		for(int i=0;i<scales.size();i++)
		{
			BradenScale scale=scales.get(i);
			scalesInfo[i][0]=scale.getName();
			scalesInfo[i][1]=Integer.toString(scale.getSensoryPerception());
			scalesInfo[i][2]=Integer.toString(scale.getMoisture());
			scalesInfo[i][3]=Integer.toString(scale.getActivity());
			scalesInfo[i][4]=Integer.toString(scale.getMobility());
			scalesInfo[i][5]=Integer.toString(scale.getNutrition());
			scalesInfo[i][6]=Integer.toString(scale.getSensoryPerception());
			
	
			
		}
		return scalesInfo;
		
		 
		 
	 }

		public String [][] getAllLabSchemeMeasurementsNames() {
			
			ArrayList<LabSchemeMeasurement> measurements=dbLabScheme.getAllLabSchemeMeasurements();
			ArrayList<String> names = new ArrayList<String>();
			
			
			for(LabSchemeMeasurement measurement: measurements)
			{
				if(!names.contains(measurement.getName()))
				      names.add(measurement.getName());
			}
			
			String [][] namesArray = new String [names.size()][1];
			
		  for(int i=0;i<names.size();i++)
		  {
			  namesArray[i][0]=names.get(i);
			  
		  }
		  
		  return namesArray;
		}
		
		public String [][] getAllNutritionRiskSchemesInformation()
		{
			ArrayList<NutritionRiskScheme> schemes=dbNutRiskScheme.getAllNutritionRiskSchemes();
			
			String [][] schemeInfo = new String [schemes.size()][3];
			
			for(int i=0;i<schemes.size();i++)
			{
				NutritionRiskScheme scheme=schemes.get(i);
				schemeInfo[i][0]=scheme.getName();
				schemeInfo[i][1]=Integer.toString(scheme.getImpNutritionStatus());
				schemeInfo[i][2]=Integer.toString(scheme.getSeverityOfDisease());
			
				
		
				
			}
			
			
			return schemeInfo;
			
			
		}
		
		public String [][]  getAllTemperatureMeasurementsNames()
		{
			ArrayList<TemperatureSchemeMeasurement> measurements=dbTempScheme.getAllTemperatureScheme();
			ArrayList<String> names = new ArrayList<String>();
			
			
			for(TemperatureSchemeMeasurement measurement: measurements)
			{
				if(!names.contains(measurement.getNameScheme()))
				      names.add(measurement.getNameScheme());
			}
			
			String [][] namesArray = new String [names.size()][1];
			
		  for(int i=0;i<names.size();i++)
		  {
			  namesArray[i][0]=names.get(i);
			  
		  }
		  
		  return namesArray;
			
		}
		
		public String [][] getNursingDocForSession(int bed_No,int room_No,String date)
		{
			Journal journal=dbJournal.findJournalAccordingBed(bed_No,room_No,date);
			ArrayList<NursingDocumentation> nursDoc=journal.getNursDoc();
			
		  String[][] nursingDocInfo= new String[13][4];
		  
		  nursingDocInfo[0][0]="Date";
		  nursingDocInfo[1][0]="Communication";
		  nursingDocInfo[2][0]="Development";
		  nursingDocInfo[3][0]="Respiration/Circulation";
		  nursingDocInfo[4][0]="Nutrition";
		  nursingDocInfo[5][0]="Excretion";
		  nursingDocInfo[6][0]="Skin Tissue";
		  nursingDocInfo[7][0]="Activity";
		  nursingDocInfo[8][0]="Sleep";
		  nursingDocInfo[9][0]="Pain/Sensation";
		  nursingDocInfo[10][0]="Sexuality/Reproductio";
		  nursingDocInfo[11][0]="Psychsocial";
		  nursingDocInfo[12][0]="Spiritual/Cultural";
		 
		  
          for(int i=0;i<nursDoc.size();i++)
          {
        	  
        	  nursingDocInfo[0][i+1]=nursDoc.get(i).getDate();
        	  nursingDocInfo[1][i+1]=nursDoc.get(i).getCommunication();
        	  nursingDocInfo[2][i+1]=nursDoc.get(i).getDevelopment();
        	  nursingDocInfo[3][i+1]=nursDoc.get(i).getRespiration_circulation();
        	  nursingDocInfo[4][i+1]=nursDoc.get(i).getNutrition();
        	  nursingDocInfo[5][i+1]=nursDoc.get(i).getExcretion();
        	  nursingDocInfo[6][i+1]=nursDoc.get(i).getSkin_tissue();
        	  nursingDocInfo[7][i+1]=nursDoc.get(i).getActivity();
        	  nursingDocInfo[8][i+1]=nursDoc.get(i).getSleep();
        	  nursingDocInfo[9][i+1]=nursDoc.get(i).getPain_sensation();
        	  nursingDocInfo[10][i+1]=nursDoc.get(i).getSexuality_reproduction();
        	  nursingDocInfo[11][i+1]=nursDoc.get(i).getPsychsocial();
        	  nursingDocInfo[12][i+1]=nursDoc.get(i).getSpiritual_cultural();
        	  
          
    		  
    		  
          }
		  
			
		  
		  return nursingDocInfo;
		}
		
		public String [][] getLabSchemesForSession(int bed_No,int room_No,String date){
			Journal journal=dbJournal.findJournalAccordingBed(bed_No,room_No,date);
			ArrayList<LabSchemeMeasurement> labSchemes=journal.getLabscheme();
			String[][] labSchemesInfo= new String[20][4];
			
			labSchemesInfo[0][0]="Date";
			labSchemesInfo[1][0]="Syre Base Status";
			labSchemesInfo[2][0]="Hemoglobin";
			labSchemesInfo[3][0]="Leukocytter";
			labSchemesInfo[4][0]="Thrombocytter";
			labSchemesInfo[5][0]="Koagulationsfaktorer";
			labSchemesInfo[6][0]="PH";
			labSchemesInfo[7][0]="Base Excess";
			labSchemesInfo[8][0]="Oxygen";
			labSchemesInfo[9][0]="Hydrogencarbonation";
			labSchemesInfo[10][0]="Kalium";
			labSchemesInfo[11][0]="Natrium";
			labSchemesInfo[12][0]="Creatininium";
			labSchemesInfo[13][0]="Carbamid";
			labSchemesInfo[14][0]="Albumin";
			labSchemesInfo[15][0]="Creaktivtprotein";
			labSchemesInfo[16][0]="Glucose 06:00";
			labSchemesInfo[17][0]="Glucose 12:00";
			labSchemesInfo[18][0]="Glucose 17:30";
			labSchemesInfo[19][0]="Glucose 21:30";
			  
	          for(int i=0;i<labSchemes.size();i++)
	          {
	        	  
	        	  labSchemesInfo[0][i+1]=labSchemes.get(i).getDate();
	        	  labSchemesInfo[1][i+1]=labSchemes.get(i).getSyre_base_status();
	        	  labSchemesInfo[2][i+1]=labSchemes.get(i).getHemoglobin();
	        	  labSchemesInfo[3][i+1]=labSchemes.get(i).getLeukocytter();
	        	  labSchemesInfo[4][i+1]=labSchemes.get(i).getThrombocytter();
	        	  labSchemesInfo[5][i+1]=labSchemes.get(i).getKoagulationsfaktorer();
	        	  labSchemesInfo[6][i+1]=labSchemes.get(i).getPh();
	        	  labSchemesInfo[7][i+1]=labSchemes.get(i).getBase_excess();
	        	  labSchemesInfo[8][i+1]=labSchemes.get(i).getOxygen();
	        	  labSchemesInfo[9][i+1]=labSchemes.get(i).getHydrogencarbonation();
	        	  labSchemesInfo[10][i+1]=labSchemes.get(i).getKalium();
	        	  labSchemesInfo[11][i+1]=labSchemes.get(i).getNatrium();
	        	  labSchemesInfo[12][i+1]=labSchemes.get(i).getCreatininium();        	  
	        	  labSchemesInfo[13][i+1]=labSchemes.get(i).getCarbamid(); 
	        	  labSchemesInfo[14][i+1]=labSchemes.get(i).getAlbumin(); 
	        	  labSchemesInfo[15][i+1]=labSchemes.get(i).getCreaktivtprotein(); 
	        	  labSchemesInfo[16][i+1]=labSchemes.get(i).getGlucose0600();
	        	  labSchemesInfo[17][i+1]=labSchemes.get(i).getGlucose1200();
	        	  labSchemesInfo[18][i+1]=labSchemes.get(i).getGlucose1730();
	        	  labSchemesInfo[19][i+1]=labSchemes.get(i).getGlucose2130(); 
	        	  
	    		  
	    		  
	          }
			  
	          return labSchemesInfo;
			
		}
		
		public String [][] getNutritionRiskForSession(int bed_No,int room_No,String date)
		{
			Journal journal=dbJournal.findJournalAccordingBed(bed_No,room_No,date);
			
			NutritionRiskScheme riskScheme=journal.getNutrisk();
			String[][] riskSchemeInfo= new String[2][2];
			
			riskSchemeInfo[0][0]="Impaired Nutritional Rusk";
			riskSchemeInfo[1][0]="Severity of Disease";
			
	    	
	    	
	    	switch (riskScheme.getImpNutritionStatus()) {
            case 0:  riskSchemeInfo[0][1]="Normal Score - 0";
                     break;
            case 1:  riskSchemeInfo[0][1] ="Easy Score - 1";
                     break;
            case 2:  riskSchemeInfo[0][1] ="Moderate Score - 2";
                     break;
            case 3:  riskSchemeInfo[0][1] ="Difficult Score - 3";
                     break;
            default:  riskSchemeInfo[0][1] = "Invalid Score";
             break;
	    	}
	
	    	switch (riskScheme.getSeverityOfDisease()) {
            case 0:  riskSchemeInfo[1][1]="Normal Score - 0";
                     break;
            case 1:  riskSchemeInfo[1][1] ="Easy Score - 1";
                     break;
            case 2:  riskSchemeInfo[1][1] ="Moderate Score - 2";
                     break;
            case 3:  riskSchemeInfo[1][1] ="Difficult Score - 3";
                     break;
            default:  riskSchemeInfo[1][1] = "Invalid Score";
             break;
	    	}

			
			
			
			
			return riskSchemeInfo;
			
			
		}
		
		public String [][] getBradenScaleForSession(int bed_No,int room_No,String date)
		{
			
			Journal journal=dbJournal.findJournalAccordingBed(bed_No,room_No,date);
			BradenScale scale=journal.getBscale();
			String[][] scaleInfo= new String[6][2];
			
			scaleInfo[0][0]="Sensory Perception";
			scaleInfo[1][0]="Moisture";
			scaleInfo[2][0]="Activity";
			scaleInfo[3][0]="Mobility";
			scaleInfo[4][0]="Nutrition";
			scaleInfo[5][0]="Friction and Shear";
			
	    	switch (scale.getSensoryPerception()) {
            case 0:  scaleInfo[0][1]="Completely Limited";
                     break;
            case 1:  scaleInfo[0][1] ="Very Limited";
                     break;
            case 2:  scaleInfo[0][1] ="Slightly Limited";
                     break;
            case 3:  scaleInfo[0][1] ="No Impairment";
                     break;
            default:  scaleInfo[0][1] = "Invalid Score";
             break;
	    	}
	    	
	    	switch (scale.getMoisture()) {
            case 0:  scaleInfo[1][1]="Constantly Moist";
                     break;
            case 1:  scaleInfo[1][1] ="Often Moist";
                     break;
            case 2:  scaleInfo[1][1] ="Occasionally Moist";
                     break;
            case 3:  scaleInfo[1][1] ="Rarely Moist";
                     break;
            default:  scaleInfo[1][1] = "Invalid Score";
             break;
	    	}
	    	
	    	switch (scale.getActivity()) {
            case 0:  scaleInfo[2][1]="Bedfast";
                     break;
            case 1:  scaleInfo[2][1] ="Chairfast";
                     break;
            case 2:  scaleInfo[2][1] ="Walks Occasionally";
                     break;
            case 3:  scaleInfo[2][1] ="Walks Frequently";
                     break;
            default:  scaleInfo[2][1] = "Invalid Score";
             break;
	    	}
	    	
	    	switch (scale.getMobility()) {
            case 0:  scaleInfo[3][1]="Completely Immobile";
                     break;
            case 1:  scaleInfo[3][1] ="Very Limited";
                     break;
            case 2:  scaleInfo[3][1] ="Slightly Limited";
                     break;
            case 3:  scaleInfo[3][1] ="No Limitations";
                     break;
            default:  scaleInfo[3][1] = "Invalid Score";
             break;
	    	}
	    	
	    	switch (scale.getNutrition()) {
            case 0:  scaleInfo[4][1]="Verry Poor";
                     break;
            case 1:  scaleInfo[4][1] ="Probably Inadequate";
                     break;
            case 2:  scaleInfo[4][1] ="Adequate";
                     break;
            case 3:  scaleInfo[4][1] ="Excellent";
                     break;
            default:  scaleInfo[4][1] = "Invalid Score";
             break;
	    	}
	    	
	    	switch (scale.getFrictionAndShear()) {
            case 0:  scaleInfo[5][1]="Problem";
                     break;
            case 1:  scaleInfo[5][1] ="Potential Problem";
                     break;
            case 2:  scaleInfo[5][1] ="No Apparent Problem";
                     break;
  
            default:  scaleInfo[5][1] = "Invalid Score";
             break;
	    	}
			
			
			
			
			
			return scaleInfo;
			
			
		}
		
		
		
	
		public ArrayList<String> getTemperature(int bed_No,int room_No,String date)
		{
			ArrayList<String> temp=new ArrayList<String>();
			int i=0;
			Journal journal=dbJournal.findJournalAccordingBed(bed_No,room_No,date);
			for (TemperatureSchemeMeasurement measurement: dbTempScheme.getTemperatureSchemeForJournal(journal)){
				temp.add( measurement.getTemperature()+"+"+measurement.getDatetime());
				
				
			}
			
			return temp;
			
			
		}
		
		public ArrayList<String> getPulse(int bed_No,int room_No,String date)
		{
			ArrayList<String> temp=new ArrayList<String>();
			int i=0;
			Journal journal=dbJournal.findJournalAccordingBed(bed_No,room_No,date);
			for (TemperatureSchemeMeasurement measurement: dbTempScheme.getTemperatureSchemeForJournal(journal)){
				temp.add( measurement.getPuls()+"+"+measurement.getDatetime());
				
				
				
			}
			
			return temp;
			
			
		}
		
		public ArrayList<String> getRespiration(int bed_No,int room_No,String date)
		{
			ArrayList<String> temp=new ArrayList<String>();
			int i=0;
			Journal journal=dbJournal.findJournalAccordingBed(bed_No,room_No,date);
			for (TemperatureSchemeMeasurement measurement: dbTempScheme.getTemperatureSchemeForJournal(journal)){
				temp.add(measurement.getRespiration()+"+"+measurement.getDatetime());
				
				
				
			}
			
			return temp;
			
			
		}
		
		
		public ArrayList<String> getBloodPressure(int bed_No,int room_No,String date)
		{
			ArrayList<String> temp=new ArrayList<String>();
			int i=0;
			Journal journal=dbJournal.findJournalAccordingBed(bed_No,room_No,date);
			for (TemperatureSchemeMeasurement measurement: dbTempScheme.getTemperatureSchemeForJournal(journal)){
				temp.add( measurement.getBlood_pressure_diastolic()+"+"+measurement.getBlood_pressure_systolic() +"+"+measurement.getDatetime());
				
				
				
			}
			
			return temp;
			
			
		}
		
		
		
		
		
		
		
}
